/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package vista;

import dao.DAOInmueble;
import dao.DAOLocalidad;
import dao.DAOPropietario;
import dao.DAOProvincia;
import entidades.Inmueble;
import entidades.Localidad;
import entidades.Propietario;
import entidades.Provincia;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author Rodri
 */
public class VAltaInmueble extends javax.swing.JDialog {

    private enum TipoAccion{
        AGREGAR,
        MODIFICAR;
    }
    TipoAccion modoVentana;

    private String num_doc;
    Inmueble inmueble;
    private JFileChooser elegirArchivo = new JFileChooser();
    private File archivo;
    private File fOut;

    /**
     * Creador de la ventana VAltaInmueble, la cual se utilizará tanto para 
     * la creacion de un inmueble para agregar al sistema, o una modificación de
     * un inmueble seleccionado previamente.
     * 
     * @param parent            elemento que llama a la funcion e instancia esta ventana
     * @param modal             booleano que indica si la ventana se crea en
     *                          modo Modal o no
     * @param inmueble          instancia de inmuelbe la cual será nula si la ventana se
    *                           crea en modo AGREGAR, de lo contrario, la instancia 
    *                           inmueble contendra la informacion con la que trabajará
    *                           la ventana
     * @param id_propietario    entero que concuerda con el id del propietario
     *                          del inmueble en caso de que la ventana se cree
     *                          en modo MODIFICAR, caso contrario su valor sera -1
     */
    public VAltaInmueble(java.awt.Frame parent, boolean modal, Inmueble inmueble, int id_propietario) {
        super(parent, modal);
        initComponents();
        
        if (inmueble == null) {
            this.inmueble = new Inmueble();
            if(id_propietario==-1){
             System.out.println("Propietario vacio");
             this.modoVentana = TipoAccion.AGREGAR;  
            }
            else{
                this.num_doc = String.valueOf(id_propietario);
                System.out.println("Propietario lleno");
                Propietario propietario = DAOPropietario.getByID(id_propietario);
                System.out.println(propietario.getApellido()+ " " + propietario.getNombre());
                this.tNombrePropietario.setText(propietario.getApellido()+ ", " + propietario.getNombre());
                this.tOculto.setText((new Integer(id_propietario)).toString());
                this.modoVentana = TipoAccion.AGREGAR;
            }
    }
        else {
            this.modoVentana = TipoAccion.MODIFICAR;
            this.inmueble=inmueble;
            
            //Precargamos los datos a modificar por el usuario
            this.tNombrePropietario.setText(inmueble.getPropietario().getApellido() + ", " + inmueble.getPropietario().getNombre());
            System.out.println("id_propietario_mod :"+inmueble.getPropietario().getIdPropietario());
            this.tOculto.setText(inmueble.getPropietario().getIdPropietario().toString());
            this.tCodigo.setText(inmueble.getCodigo());
            
            // recorro el combobox provincia para que coincida con el del inmueble
            int cbTam = this.cbProvincia.getItemCount();
            int index = 0;
            for (; index < cbTam; index++)
                if (this.cbProvincia.getModel().getElementAt(index).equals(inmueble.getLocalidad().getProvincia().getNombre())){
                    this.cbProvincia.setSelectedIndex(index);
                    break;
                }
            
            // cargo las localidades de la provincia del inmueble para realizar una busqueda luego
            Set localidades = VPrincipal.provincias.get(index).getLocalidads();
            Iterator i = localidades.iterator();

            cbLocalidad.removeAllItems();

            while(i.hasNext()) {
                this.cbLocalidad.addItem(((Localidad) i.next()).getNombre());
            }
            this.cbLocalidad.setEnabled(true);

            cbTam = this.cbLocalidad.getItemCount();
            for (index = 0; index < cbTam; index++)
                if (this.cbLocalidad.getModel().getElementAt(index).equals(inmueble.getLocalidad().getNombre())){
                    this.cbLocalidad.setSelectedIndex(index);
                    break;
                }
            
            this.tCalle.setText(inmueble.getCalle());
            this.tNumero.setText(inmueble.getNumero().toString());
            this.tPiso.setText(inmueble.getPiso().toString());
            this.tDepartamento.setText(inmueble.getDepartamento());
            this.tBarrio.setText(inmueble.getBarrio());
            //this.cbOrientacion.setSelectedIndex(inmueble.getOrientacionEnum().ordinal());
            this.cbOrientacion.setSelectedIndex(DAOInmueble.getOrientacionEnum(inmueble.getOrientacion()).ordinal());
            System.out.println(DAOInmueble.getOrientacionEnum(inmueble.getOrientacion()).ordinal());
            this.cbTipo.setSelectedIndex(DAOInmueble.getInmuebleTipoEnum(inmueble.getTipo()).ordinal());
            
            this.tMonto.setText(String.valueOf(inmueble.getPrecio()));
            this.tFrente.setText(String.valueOf(inmueble.getFrente()));
            this.tFondo.setText(String.valueOf(inmueble.getFondo()));
            this.tSuperficie.setText(String.valueOf(inmueble.getSuperficie()));
            this.tAntiguedad.setText(String.valueOf(inmueble.getAntiguedad()));
            this.chbPropiedadHorizontal.setSelected(inmueble.isPropiedadHorizontal());
            this.tDormitorios.setText(String.valueOf(inmueble.getDormitorios()));
            this.tBanos.setText(String.valueOf(inmueble.getBanos()));
            this.chbGarage.setSelected(inmueble.isGarage());
            this.chbPatio.setSelected(inmueble.isPatio());
            this.chbPiscina.setSelected(inmueble.isPiscina());
            this.chbAguaCorriente.setSelected(inmueble.isAguaCorriente());
            this.chbCloacas.setSelected(inmueble.isCloacas());
            this.chbGasNatural.setSelected(inmueble.isGas());
            this.chbAguaCaliente.setSelected(inmueble.isAguaCaliente());
            this.chbLavedor.setSelected(inmueble.isLavadero());
            this.chbPavimento.setSelected(inmueble.isPavimento());
            this.chbTelefono.setSelected(inmueble.isTelefono());
        }
    }

    public void setIdPropietario(String dniPropietario)
    {
        this.num_doc = dniPropietario;
        inmueble.setPropietario(DAOPropietario.getByNumDoc(num_doc));
        //inmueble.setPropietario(DAOPropietario.getByNumDoc(this.num_doc));
        System.out.println("NUMERODOC PROPIETARIO: "+inmueble.getPropietario().getNumDoc());
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pPropietario = new javax.swing.JPanel();
        lNombrePropietario = new javax.swing.JLabel();
        tNombrePropietario = new javax.swing.JTextField();
        btnBuscar = new javax.swing.JButton();
        pUbicacion = new javax.swing.JPanel();
        lProvincia = new javax.swing.JLabel();
        cbProvincia = new javax.swing.JComboBox();
        lLocalidad = new javax.swing.JLabel();
        cbLocalidad = new javax.swing.JComboBox();
        lCalle = new javax.swing.JLabel();
        tCalle = new javax.swing.JTextField();
        lNumero = new javax.swing.JLabel();
        tNumero = new javax.swing.JTextField();
        lPiso = new javax.swing.JLabel();
        tPiso = new javax.swing.JTextField();
        lDepartamento = new javax.swing.JLabel();
        tDepartamento = new javax.swing.JTextField();
        lBarrio = new javax.swing.JLabel();
        tBarrio = new javax.swing.JTextField();
        lOrientacion = new javax.swing.JLabel();
        cbOrientacion = new javax.swing.JComboBox();
        pCaracteristicas = new javax.swing.JPanel();
        lTipo = new javax.swing.JLabel();
        cbTipo = new javax.swing.JComboBox();
        lMonto = new javax.swing.JLabel();
        tMonto = new javax.swing.JTextField();
        lFrente = new javax.swing.JLabel();
        tFrente = new javax.swing.JTextField();
        lFondo = new javax.swing.JLabel();
        tFondo = new javax.swing.JTextField();
        lSuperficie = new javax.swing.JLabel();
        tSuperficie = new javax.swing.JTextField();
        lM2 = new javax.swing.JLabel();
        chbPropiedadHorizontal = new javax.swing.JCheckBox();
        lAntiguedad = new javax.swing.JLabel();
        tAntiguedad = new javax.swing.JTextField();
        lAnos = new javax.swing.JLabel();
        lDormitorios = new javax.swing.JLabel();
        lBanos = new javax.swing.JLabel();
        tDormitorios = new javax.swing.JTextField();
        tBanos = new javax.swing.JTextField();
        chbGarage = new javax.swing.JCheckBox();
        chbPatio = new javax.swing.JCheckBox();
        chbAguaCorriente = new javax.swing.JCheckBox();
        chbAguaCaliente = new javax.swing.JCheckBox();
        chbCloacas = new javax.swing.JCheckBox();
        chbLavedor = new javax.swing.JCheckBox();
        chbPiscina = new javax.swing.JCheckBox();
        chbGasNatural = new javax.swing.JCheckBox();
        chbPavimento = new javax.swing.JCheckBox();
        chbTelefono = new javax.swing.JCheckBox();
        bCancelar = new javax.swing.JButton();
        bGuardar = new javax.swing.JButton();
        pCodigo = new javax.swing.JPanel();
        lCodigo = new javax.swing.JLabel();
        tCodigo = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        tOculto = new javax.swing.JTextField();
        bImagen = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Alta Inmueble");
        setName("vAltaInmueble"); // NOI18N

        pPropietario.setBorder(javax.swing.BorderFactory.createTitledBorder("Propietario"));

        lNombrePropietario.setText("Nombre Completo:");

        tNombrePropietario.setEditable(false);
        tNombrePropietario.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tNombrePropietarioMouseClicked(evt);
            }
        });
        tNombrePropietario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tNombrePropietarioActionPerformed(evt);
            }
        });

        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/search_button_green_16.png"))); // NOI18N
        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pPropietarioLayout = new javax.swing.GroupLayout(pPropietario);
        pPropietario.setLayout(pPropietarioLayout);
        pPropietarioLayout.setHorizontalGroup(
            pPropietarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pPropietarioLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lNombrePropietario)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tNombrePropietario, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnBuscar))
        );
        pPropietarioLayout.setVerticalGroup(
            pPropietarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pPropietarioLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pPropietarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lNombrePropietario)
                    .addComponent(tNombrePropietario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBuscar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pUbicacion.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos de Ubicación"));

        lProvincia.setText("Provincia:");

        cbProvincia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "BUENOS AIRES", "CATAMARCA", "CHACO", "CHUBUT", "CORDOBA", "CORRIENTES", "ENTRE RIOS", "FORMOSA", "JUJUY", "LA PAMPA", "LA RIOJA", "MENDOZA", "MISIONES", "NEUQUEN", "RIO NEGRO", "SALTA", "SAN JUAN", "SAN LUIS", "SANTA CRUZ", "SANTA FE", "SANTIAGO DEL ESTERO", "TIERRA DEL FUEGO", "TUCUMAN" }));
        cbProvincia.setSelectedIndex(-1);
        cbProvincia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbProvinciaActionPerformed(evt);
            }
        });

        lLocalidad.setText("Localidad:");

        cbLocalidad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccone una Provincia" }));
        cbLocalidad.setEnabled(false);

        lCalle.setText("Calle:");

        tCalle.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tCalleKeyTyped(evt);
            }
        });

        lNumero.setText("Nro:");

        tNumero.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tNumeroKeyTyped(evt);
            }
        });

        lPiso.setText("Piso:");

        tPiso.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tPisoKeyTyped(evt);
            }
        });

        lDepartamento.setText("Dpto:");

        tDepartamento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tDepartamentoKeyTyped(evt);
            }
        });

        lBarrio.setText("Barrio:");

        tBarrio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tBarrioKeyTyped(evt);
            }
        });

        lOrientacion.setText("Orientación:");

        cbOrientacion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NORTE", "SUR", "ESTE", "OESTE", "NORESTE", "NOROESTE", "SURESTE", "SUROESTE" }));
        cbOrientacion.setSelectedIndex(-1);
        cbOrientacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbOrientacionActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pUbicacionLayout = new javax.swing.GroupLayout(pUbicacion);
        pUbicacion.setLayout(pUbicacionLayout);
        pUbicacionLayout.setHorizontalGroup(
            pUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pUbicacionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lBarrio)
                    .addComponent(lCalle)
                    .addComponent(lProvincia))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(cbProvincia, 0, 154, Short.MAX_VALUE)
                    .addComponent(tCalle)
                    .addComponent(tBarrio))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pUbicacionLayout.createSequentialGroup()
                        .addComponent(lLocalidad)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbLocalidad, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pUbicacionLayout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addGroup(pUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pUbicacionLayout.createSequentialGroup()
                                .addComponent(lOrientacion)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbOrientacion, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pUbicacionLayout.createSequentialGroup()
                                .addComponent(lNumero)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lPiso)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tPiso, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(lDepartamento)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tDepartamento, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pUbicacionLayout.setVerticalGroup(
            pUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pUbicacionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lProvincia)
                    .addComponent(cbProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lLocalidad)
                    .addComponent(cbLocalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lCalle)
                    .addComponent(tCalle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lNumero)
                    .addComponent(tNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lPiso)
                    .addComponent(tPiso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lDepartamento)
                    .addComponent(tDepartamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lBarrio)
                    .addComponent(tBarrio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lOrientacion)
                    .addComponent(cbOrientacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        cbProvincia.getAccessibleContext().setAccessibleName("cbProvincia");
        cbLocalidad.getAccessibleContext().setAccessibleName("cbLocalidad");
        cbOrientacion.getAccessibleContext().setAccessibleName("cbOrientacion");

        pCaracteristicas.setBorder(javax.swing.BorderFactory.createTitledBorder("Características"));

        lTipo.setText("Tipo de Inmueble:");

        cbTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Local/Oficina", "Casa", "Departamento", "Terreno", "Quinta", "Galpon" }));
        cbTipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTipoActionPerformed(evt);
            }
        });

        lMonto.setText("Monto: $");

        tMonto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tMontoKeyTyped(evt);
            }
        });

        lFrente.setText("Metros de Frente:");

        tFrente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tFrenteKeyTyped(evt);
            }
        });

        lFondo.setText("Metros de Fondo:");

        tFondo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tFondoKeyTyped(evt);
            }
        });

        lSuperficie.setText("Superficie:");

        tSuperficie.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tSuperficieKeyTyped(evt);
            }
        });

        lM2.setText("m2");

        chbPropiedadHorizontal.setText("Propiedad Horizontal");

        lAntiguedad.setText("Antigüedad:");

        tAntiguedad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tAntiguedadKeyTyped(evt);
            }
        });

        lAnos.setText("años");

        lDormitorios.setText("Dormitorios:");

        lBanos.setText("Baños:");

        tDormitorios.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tDormitoriosKeyTyped(evt);
            }
        });

        tBanos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tBanosKeyTyped(evt);
            }
        });

        chbGarage.setText("Garage / Cochera");

        chbPatio.setText("Patio");

        chbAguaCorriente.setText("Agua corriente");

        chbAguaCaliente.setText("Agua caliente");

        chbCloacas.setText("Cloacas");

        chbLavedor.setText("Lavadero");

        chbPiscina.setText("Piscina");

        chbGasNatural.setText("Gas Natural");

        chbPavimento.setText("Pavimento");

        chbTelefono.setText("Teléfono");

        javax.swing.GroupLayout pCaracteristicasLayout = new javax.swing.GroupLayout(pCaracteristicas);
        pCaracteristicas.setLayout(pCaracteristicasLayout);
        pCaracteristicasLayout.setHorizontalGroup(
            pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pCaracteristicasLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(pCaracteristicasLayout.createSequentialGroup()
                            .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(pCaracteristicasLayout.createSequentialGroup()
                                    .addComponent(lTipo)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(cbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(pCaracteristicasLayout.createSequentialGroup()
                                    .addComponent(lFrente)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(tFrente)))
                            .addGap(18, 18, 18)
                            .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(pCaracteristicasLayout.createSequentialGroup()
                                    .addComponent(lMonto)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(tMonto, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(pCaracteristicasLayout.createSequentialGroup()
                                    .addComponent(lFondo)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(tFondo))))
                        .addGroup(pCaracteristicasLayout.createSequentialGroup()
                            .addComponent(lSuperficie)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(tSuperficie, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lM2)
                            .addGap(18, 18, 18)
                            .addComponent(chbPropiedadHorizontal))
                        .addGroup(pCaracteristicasLayout.createSequentialGroup()
                            .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(pCaracteristicasLayout.createSequentialGroup()
                                    .addComponent(lAntiguedad)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(tAntiguedad, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(lAnos))
                                .addGroup(pCaracteristicasLayout.createSequentialGroup()
                                    .addComponent(chbGarage)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(chbPatio))
                                .addGroup(pCaracteristicasLayout.createSequentialGroup()
                                    .addComponent(chbAguaCorriente)
                                    .addGap(18, 18, 18)
                                    .addComponent(chbCloacas))
                                .addGroup(pCaracteristicasLayout.createSequentialGroup()
                                    .addComponent(chbAguaCaliente)
                                    .addGap(24, 24, 24)
                                    .addComponent(chbLavedor)))
                            .addGap(18, 18, 18)
                            .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(pCaracteristicasLayout.createSequentialGroup()
                                    .addComponent(lDormitorios)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(tDormitorios, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(lBanos)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(tBanos, javax.swing.GroupLayout.DEFAULT_SIZE, 73, Short.MAX_VALUE))
                                .addGroup(pCaracteristicasLayout.createSequentialGroup()
                                    .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(chbGasNatural)
                                        .addComponent(chbPiscina)
                                        .addComponent(chbPavimento))
                                    .addGap(0, 0, Short.MAX_VALUE)))))
                    .addComponent(chbTelefono))
                .addContainerGap(25, Short.MAX_VALUE))
        );
        pCaracteristicasLayout.setVerticalGroup(
            pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pCaracteristicasLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lTipo)
                    .addComponent(cbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lMonto)
                    .addComponent(tMonto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lFrente)
                    .addComponent(tFrente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lFondo)
                    .addComponent(tFondo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lSuperficie)
                    .addComponent(tSuperficie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lM2)
                    .addComponent(chbPropiedadHorizontal))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lAntiguedad)
                    .addComponent(tAntiguedad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lAnos)
                    .addComponent(lDormitorios)
                    .addComponent(lBanos)
                    .addComponent(tDormitorios, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tBanos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chbGarage)
                    .addComponent(chbPatio)
                    .addComponent(chbPiscina))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chbAguaCorriente)
                    .addComponent(chbCloacas)
                    .addComponent(chbGasNatural))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pCaracteristicasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chbAguaCaliente)
                    .addComponent(chbLavedor)
                    .addComponent(chbPavimento))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(chbTelefono))
        );

        cbTipo.getAccessibleContext().setAccessibleName("lbTipo");
        chbPropiedadHorizontal.getAccessibleContext().setAccessibleName("cbPropiedad");
        chbGarage.getAccessibleContext().setAccessibleName("cbGarage");
        chbPatio.getAccessibleContext().setAccessibleName("clPatio");
        chbAguaCorriente.getAccessibleContext().setAccessibleName("clAgua");
        chbAguaCaliente.getAccessibleContext().setAccessibleName("clAguaCaliente");
        chbCloacas.getAccessibleContext().setAccessibleName("clCloacas");
        chbLavedor.getAccessibleContext().setAccessibleName("clLavadero");
        chbPiscina.getAccessibleContext().setAccessibleName("clPiscina");
        chbGasNatural.getAccessibleContext().setAccessibleName("clGas");
        chbPavimento.getAccessibleContext().setAccessibleName("clPavimento");

        bCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/close_16.png"))); // NOI18N
        bCancelar.setText("Cancelar");
        bCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bCancelarActionPerformed(evt);
            }
        });

        bGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/disk.png"))); // NOI18N
        bGuardar.setText("Guardar");
        bGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bGuardarActionPerformed(evt);
            }
        });

        pCodigo.setBorder(javax.swing.BorderFactory.createTitledBorder("Código"));

        lCodigo.setText("Código Único de Inmueble:");

        tCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tCodigoKeyTyped(evt);
            }
        });

        tOculto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tOcultoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pCodigoLayout = new javax.swing.GroupLayout(pCodigo);
        pCodigo.setLayout(pCodigoLayout);
        pCodigoLayout.setHorizontalGroup(
            pCodigoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pCodigoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lCodigo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 179, Short.MAX_VALUE)
                .addComponent(tOculto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1)
                .addContainerGap())
        );
        pCodigoLayout.setVerticalGroup(
            pCodigoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lCodigo)
            .addGroup(pCodigoLayout.createSequentialGroup()
                .addGap(2, 2, 2)
                .addGroup(pCodigoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(tOculto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        tOculto.hide();
        tOculto.disable();

        bImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/add_16.png"))); // NOI18N
        bImagen.setText("Agregar Imagen");
        bImagen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bImagenActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(bImagen)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(bGuardar)
                .addGap(2, 2, 2)
                .addComponent(bCancelar))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(pCaracteristicas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pUbicacion, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 468, Short.MAX_VALUE)
                    .addComponent(pPropietario, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pCodigo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pPropietario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(pUbicacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pCaracteristicas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bCancelar)
                    .addComponent(bGuardar)
                    .addComponent(bImagen))
                .addContainerGap())
        );

        setSize(new java.awt.Dimension(494, 574));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void cbOrientacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbOrientacionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbOrientacionActionPerformed

    /**
     * Funcion que mediante el evento de presionar el boton buscar propietario instancia
     * una ventana VBuscarPersona para realizar la busqueda del propietario correspondiente
     * al inmueble que se desea que agregar o modificar en el sistema
     * 
     * @param evt   evento del presionado del boton buscar propietario
     */
    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        VBuscarPersona vBc = new VBuscarPersona(this, "Propietario");
        vBc.setVisible(true);
        
        Propietario p = DAOPropietario.getByNumDoc(this.num_doc);
        
        this.tNombrePropietario.setText(p.getApellido()+", "+p.getNombre());
    }//GEN-LAST:event_btnBuscarActionPerformed

private void cbTipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTipoActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_cbTipoActionPerformed

private void bCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCancelarActionPerformed
    this.dispose();
}//GEN-LAST:event_bCancelarActionPerformed

    
    private void cbProvinciaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbProvinciaActionPerformed
        int provincia_seleccionada = cbProvincia.getSelectedIndex();
        
        Set localidades = VPrincipal.provincias.get(provincia_seleccionada).getLocalidads();
        Iterator i = localidades.iterator();
        
        cbLocalidad.removeAllItems();
        
        while(i.hasNext()) {
            this.cbLocalidad.addItem(((Localidad) i.next()).getNombre());
        }

        this.cbLocalidad.setSelectedIndex(-1);
        this.cbLocalidad.setEnabled(true);
    }//GEN-LAST:event_cbProvinciaActionPerformed

    private void tNombrePropietarioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tNombrePropietarioMouseClicked
        VBuscarPersona vBc = new VBuscarPersona(this, "Propietario");
        this.setVisible(false);
        vBc.setVisible(true);
    }//GEN-LAST:event_tNombrePropietarioMouseClicked

    private void tNombrePropietarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tNombrePropietarioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tNombrePropietarioActionPerformed

    private void tOcultoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tOcultoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tOcultoActionPerformed

    private void bGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGuardarActionPerformed
       //Chequear datos de entrada
       String codigo = tCodigo.getText();
       String calle = tCalle.getText();
       Integer numero_calle = new Integer(0); 
       Integer piso = new Integer(0);  
       String dpto = tDepartamento.getText();
       String barrio = tBarrio.getText();
       int orientacion_seleccionada = cbOrientacion.getSelectedIndex();
       int tipo_inmueble_seleccionado = cbTipo.getSelectedIndex();
       Float monto = new Float(0);          
       Double metros_frente = new Double(0);   
       Double metros_fondo = new Double(0);    
       Double superficie = new Double(0);      
       Integer antiguedad = new Integer(0);  
       Integer cant_banos = new Integer(0);      //////tiene que ser tipo BYTE
       Integer cant_dormitorios = new Integer(0);    //tiene que ser tipo BYTE
           
       if(tNombrePropietario.getText().isEmpty()){
           JOptionPane.showMessageDialog(this, "Debe seleccionar un Propietario", "Error! Propietario", JOptionPane.ERROR_MESSAGE);
           return;
       }
       if(codigo.isEmpty()){
           JOptionPane.showMessageDialog(this, "Debe nombrar un Codigo Unico de Inmueble", "Error! Codigo de Inmueble", JOptionPane.ERROR_MESSAGE);
           return;
       }
       if(cbProvincia.getSelectedIndex() < 0){
           JOptionPane.showMessageDialog(this, "Debe seleccionar una Provincia", "Error! Provincia", JOptionPane.ERROR_MESSAGE);
           return;
       }
       if(cbLocalidad.getSelectedIndex() < 1){
           JOptionPane.showMessageDialog(this, "Debe seleccionar una Localidad", "Error! Localidad", JOptionPane.ERROR_MESSAGE);
           return;
       }
       if(calle.isEmpty()){
           JOptionPane.showMessageDialog(this, "Debe nombrar la calle", "Error! Calle Inmueble", JOptionPane.ERROR_MESSAGE);
           return;
       }
       if(cbOrientacion.getSelectedIndex() < 0){
           JOptionPane.showMessageDialog(this, "Debe seleccionar una Orientacion", "Error! Orientacion", JOptionPane.ERROR_MESSAGE);
           return;
       }
       if(barrio.isEmpty()){
           JOptionPane.showMessageDialog(this, "Debe completar el nombre del Barrio", "Error! Barrio", JOptionPane.ERROR_MESSAGE);
           return;
       }
       if(cbTipo.getSelectedIndex() < 0){
           JOptionPane.showMessageDialog(this, "Debe seleccionar un Tipo de Inmueble", "Error! Tipo de Inmueble", JOptionPane.ERROR_MESSAGE);
           return;
       }
       if(!tNumero.getText().isEmpty()) {
            try {
                numero_calle = Integer.parseInt(tNumero.getText());
                tNumero.setForeground(Color.black);
            }
            catch(Exception e) {
                JOptionPane.showMessageDialog(this, "El numero de calle debe ser un número entero", "Error! Numero de calle", JOptionPane.ERROR_MESSAGE);
                tNumero.setForeground(Color.red);
                return;
            }
       }
       else{
           JOptionPane.showMessageDialog(this, "El numero de calle debe ser completado", "Error! Número de calle", JOptionPane.ERROR_MESSAGE);
           return;
       }
            
       if(!tPiso.getText().isEmpty()) {
           try{
                piso = Integer.parseInt(tPiso.getText());
                tPiso.setForeground(Color.black);
           }
           catch(Exception e) {
                JOptionPane.showMessageDialog(this, "El Piso debe ser un número entero", "Error! Piso", JOptionPane.ERROR_MESSAGE);
                tNumero.setForeground(Color.red);
                return;
            }
       }
             
       if(!tMonto.getText().isEmpty()) {
            try {
                monto = Float.parseFloat(tMonto.getText());
                tMonto.setForeground(Color.black);
            }
            catch(Exception e) {
                JOptionPane.showMessageDialog(this, "El precio debe ser un número", "Error! Rango inferior del precio", JOptionPane.ERROR_MESSAGE);
                tMonto.setForeground(Color.red);
                return;
            }
        }
        else{
           JOptionPane.showMessageDialog(this, "El Monto debe ser completado", "Error! Monto", JOptionPane.ERROR_MESSAGE);
           return;
       }
       
        if(!tFrente.getText().isEmpty()) {
            try {
                metros_frente = Double.parseDouble(tFrente.getText());
                tFrente.setForeground(Color.black);
            }
            catch(Exception e) {
                JOptionPane.showMessageDialog(this, "La cantidad de metros de frente debe ser un número", "Error! Cantidad de metros de frente", JOptionPane.ERROR_MESSAGE);
                tFrente.setForeground(Color.red);
                return;
            }
        }
        else{
           JOptionPane.showMessageDialog(this, "Los metros de frente debe ser completado", "Error! Metros de Frente", JOptionPane.ERROR_MESSAGE);
           return;
       }
       
        if(!tFondo.getText().isEmpty()) {
            try {
                metros_fondo = Double.parseDouble(tFondo.getText());
                tFondo.setForeground(Color.black);
            }
            catch(Exception e) {
                JOptionPane.showMessageDialog(this, "La cantidad de metros de fondo debe ser un número", "Error! Cantidad de metros de fondo", JOptionPane.ERROR_MESSAGE);
                tFondo.setForeground(Color.red);
                return;
            }
        }
        else{
           JOptionPane.showMessageDialog(this, "Los metros de fondo debe ser completado", "Error! Metros de Fondo", JOptionPane.ERROR_MESSAGE);
           return;
       }
        
        if(!tSuperficie.getText().isEmpty()) {
            try {
                superficie = Double.parseDouble(tSuperficie.getText());
                tSuperficie.setForeground(Color.black);
            }
            catch(Exception e) {
                JOptionPane.showMessageDialog(this, "La cantidad de metros cubicos de seperficie debe ser un número", "Error! Cantidad de metros cubicos de superficie", JOptionPane.ERROR_MESSAGE);
                tSuperficie.setForeground(Color.red);
                return;
            }
        }
        else{
           JOptionPane.showMessageDialog(this, "La Superficie debe ser completado", "Error! Superficie", JOptionPane.ERROR_MESSAGE);
           return;
       }
        
        if(!tAntiguedad.getText().isEmpty()) {
            try {
                antiguedad = Integer.parseInt(tAntiguedad.getText());
                tAntiguedad.setForeground(Color.black);
            }
            catch(Exception e) {
                JOptionPane.showMessageDialog(this, "La cantidad de años de antiguedad debe ser un número entero", "Error! Cantidad de años de antiguedad", JOptionPane.ERROR_MESSAGE);
                tAntiguedad.setForeground(Color.red);
                return;
            }
       }
       else{
           JOptionPane.showMessageDialog(this, "Los años de antiguedad debe ser completado", "Error! Antiguedad", JOptionPane.ERROR_MESSAGE);
           return;
       }
        
       if(!tBanos.getText().isEmpty()) {
            try {
                cant_banos = Integer.parseInt(tBanos.getText());
                tBanos.setForeground(Color.black);
            }
            catch(Exception e) {
                JOptionPane.showMessageDialog(this, "La cantidad de baños debe ser un número entero", "Error! Cantidad de baños", JOptionPane.ERROR_MESSAGE);
                tBanos.setForeground(Color.red);
                return;
            }
       }
        
       if(!tDormitorios.getText().isEmpty()) {
            try {
                cant_dormitorios = Integer.parseInt(tDormitorios.getText());
                tDormitorios.setForeground(Color.black);
            }
            catch(Exception e) {
                JOptionPane.showMessageDialog(this, "La cantidad de dormitorios debe ser un número entero", "Error! Cantidad de dormitorios", JOptionPane.ERROR_MESSAGE);
                tDormitorios.setForeground(Color.red);
                return;
            }
       }    
 
       //Armamos instancia para cargar datos
       Provincia provincia = DAOProvincia.getByNombre(cbProvincia.getSelectedItem().toString());
       Localidad localidad;
       localidad = DAOLocalidad.getByProvinciaLocalidad(provincia.getIdProvincia(), cbLocalidad.getSelectedItem().toString());
       System.out.println("Localidad: "+localidad.getNombre());
       System.out.println("id_localidad: "+localidad.getIdLocalidad());
       System.out.println("provincia: "+localidad.getProvincia());
       

       inmueble.setLocalidad(localidad);
       inmueble.setCodigo(codigo); 
       inmueble.setCalle(calle);
       inmueble.setNumero(Short.parseShort(numero_calle.toString()));
       inmueble.setPiso(Byte.parseByte(piso.toString()));
       inmueble.setDepartamento(dpto);
       inmueble.setBarrio(barrio);
       inmueble.setTipo(DAOInmueble.setInmuebleTipoEnum(tipo_inmueble_seleccionado));
       inmueble.setPrecio(monto);
       inmueble.setOrientacion(DAOInmueble.setOrientacionEnum(orientacion_seleccionada));
       inmueble.setFrente(metros_frente); 
       inmueble.setFondo(metros_fondo); 
       inmueble.setSuperficie(superficie); 
       inmueble.setPropiedadHorizontal(chbPropiedadHorizontal.isSelected());
       inmueble.setAntiguedad(antiguedad); 
       inmueble.setDormitorios(Byte.parseByte(cant_dormitorios.toString())); 
       inmueble.setBanos(Byte.parseByte(cant_banos.toString())); 
       inmueble.setGarage(chbGarage.isSelected());
       inmueble.setPatio(chbPatio.isSelected()); 
       inmueble.setPiscina(chbPiscina.isSelected()); 
       inmueble.setAguaCorriente(chbAguaCorriente.isSelected()); 
       inmueble.setCloacas(chbCloacas.isSelected());
       inmueble.setGas(chbGasNatural.isSelected()); 
       inmueble.setAguaCaliente(chbAguaCaliente.isSelected());
       inmueble.setTelefono(chbTelefono.isSelected()); 
       inmueble.setLavadero(chbLavedor.isSelected()); 
       inmueble.setPavimento(chbPavimento.isSelected());

       if(this.modoVentana == TipoAccion.AGREGAR){

           DAOInmueble.insert(inmueble);
           int ultimoId = DAOInmueble.getMaxId().getIdInmueble();
           fOut = new File(System.getProperty("user.dir")+"\\imagenes\\"+ultimoId+"_1.jpg");
           copyFile(archivo,fOut);
           System.out.println("Datos Agregado");
           this.dispose();
       }
       if(this.modoVentana == TipoAccion.MODIFICAR){
                    
           DAOInmueble.update(inmueble);
           int Id = DAOInmueble.getByCodigo(inmueble.getCodigo()).getIdInmueble();
           fOut = new File(System.getProperty("user.dir")+"\\imagenes\\"+Id+"_1.jpg");
           copyFile(archivo,fOut);
           System.out.println("Datos Modificado");
           this.dispose();
       }
    }//GEN-LAST:event_bGuardarActionPerformed

    private void bImagenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bImagenActionPerformed
        FileFilter filtro = new ExtensionFilter("Archivos de imagen (JPG, PNG)",
            new String[] { ".jpg", ".png"});
        
        
        int ultimoId;
        
        elegirArchivo.setFileFilter(filtro);
        int returnVal = elegirArchivo.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
                archivo = elegirArchivo.getSelectedFile();
                
                
        }
    }//GEN-LAST:event_bImagenActionPerformed

    private void tCodigoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tCodigoKeyTyped
        if (this.tCodigo.getText().length() == 8)
            evt.consume();        // TODO add your handling code here:
    }//GEN-LAST:event_tCodigoKeyTyped

    private void tCalleKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tCalleKeyTyped
        if (this.tCalle.getText().length() == 40)
            evt.consume(); 
    }//GEN-LAST:event_tCalleKeyTyped

    private void tNumeroKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tNumeroKeyTyped
        if (this.tNumero.getText().length() == 5)
            evt.consume();
    }//GEN-LAST:event_tNumeroKeyTyped

    private void tPisoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tPisoKeyTyped
        if (this.tPiso.getText().length() == 2)
            evt.consume();
    }//GEN-LAST:event_tPisoKeyTyped

    private void tDepartamentoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tDepartamentoKeyTyped
        if (this.tDepartamento.getText().length() == 3)
            evt.consume();
    }//GEN-LAST:event_tDepartamentoKeyTyped

    private void tBarrioKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tBarrioKeyTyped
        if (this.tBarrio.getText().length() == 30)
            evt.consume();
    }//GEN-LAST:event_tBarrioKeyTyped

    private void tMontoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tMontoKeyTyped
        if (this.tMonto.getText().length() == 9)
            evt.consume();
    }//GEN-LAST:event_tMontoKeyTyped

    private void tFrenteKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tFrenteKeyTyped
        if (this.tFrente.getText().length() == 6)
            evt.consume();
    }//GEN-LAST:event_tFrenteKeyTyped

    private void tFondoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tFondoKeyTyped
        if (this.tFondo.getText().length() == 6)
            evt.consume();
    }//GEN-LAST:event_tFondoKeyTyped

    private void tSuperficieKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tSuperficieKeyTyped
        if (this.tSuperficie.getText().length() == 6)
            evt.consume();
    }//GEN-LAST:event_tSuperficieKeyTyped

    private void tAntiguedadKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tAntiguedadKeyTyped
        if (this.tAntiguedad.getText().length() == 2)
            evt.consume();
    }//GEN-LAST:event_tAntiguedadKeyTyped

    private void tDormitoriosKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tDormitoriosKeyTyped
        if (this.tDormitorios.getText().length() == 2)
            evt.consume();
    }//GEN-LAST:event_tDormitoriosKeyTyped

    private void tBanosKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tBanosKeyTyped
        if (this.tBanos.getText().length() == 2)
            evt.consume(); 
    }//GEN-LAST:event_tBanosKeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VAltaInmueble.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VAltaInmueble.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VAltaInmueble.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VAltaInmueble.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                VAltaInmueble dialog = new VAltaInmueble(new javax.swing.JFrame(), true, null, -1);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
 public void copyFile(File s, File t)
    {
        try{
              FileChannel in = (new FileInputStream(s)).getChannel();
              FileChannel out = (new FileOutputStream(t)).getChannel();
              in.transferTo(0, s.length(), out);
              in.close();
              out.close();
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bCancelar;
    private javax.swing.JButton bGuardar;
    private javax.swing.JButton bImagen;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JComboBox cbLocalidad;
    private javax.swing.JComboBox cbOrientacion;
    private javax.swing.JComboBox cbProvincia;
    private javax.swing.JComboBox cbTipo;
    private javax.swing.JCheckBox chbAguaCaliente;
    private javax.swing.JCheckBox chbAguaCorriente;
    private javax.swing.JCheckBox chbCloacas;
    private javax.swing.JCheckBox chbGarage;
    private javax.swing.JCheckBox chbGasNatural;
    private javax.swing.JCheckBox chbLavedor;
    private javax.swing.JCheckBox chbPatio;
    private javax.swing.JCheckBox chbPavimento;
    private javax.swing.JCheckBox chbPiscina;
    private javax.swing.JCheckBox chbPropiedadHorizontal;
    private javax.swing.JCheckBox chbTelefono;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel lAnos;
    private javax.swing.JLabel lAntiguedad;
    private javax.swing.JLabel lBanos;
    private javax.swing.JLabel lBarrio;
    private javax.swing.JLabel lCalle;
    private javax.swing.JLabel lCodigo;
    private javax.swing.JLabel lDepartamento;
    private javax.swing.JLabel lDormitorios;
    private javax.swing.JLabel lFondo;
    private javax.swing.JLabel lFrente;
    private javax.swing.JLabel lLocalidad;
    private javax.swing.JLabel lM2;
    private javax.swing.JLabel lMonto;
    private javax.swing.JLabel lNombrePropietario;
    private javax.swing.JLabel lNumero;
    private javax.swing.JLabel lOrientacion;
    private javax.swing.JLabel lPiso;
    private javax.swing.JLabel lProvincia;
    private javax.swing.JLabel lSuperficie;
    private javax.swing.JLabel lTipo;
    private javax.swing.JPanel pCaracteristicas;
    private javax.swing.JPanel pCodigo;
    private javax.swing.JPanel pPropietario;
    private javax.swing.JPanel pUbicacion;
    private javax.swing.JTextField tAntiguedad;
    private javax.swing.JTextField tBanos;
    private javax.swing.JTextField tBarrio;
    private javax.swing.JTextField tCalle;
    private javax.swing.JTextField tCodigo;
    private javax.swing.JTextField tDepartamento;
    private javax.swing.JTextField tDormitorios;
    private javax.swing.JTextField tFondo;
    private javax.swing.JTextField tFrente;
    private javax.swing.JTextField tMonto;
    private javax.swing.JTextField tNombrePropietario;
    private javax.swing.JTextField tNumero;
    private javax.swing.JTextField tOculto;
    private javax.swing.JTextField tPiso;
    private javax.swing.JTextField tSuperficie;
    // End of variables declaration//GEN-END:variables
}
